package com.wteam.dragon.model.controller;

import com.wteam.dragon.model.pojo.bean.ArticleType;
import com.wteam.dragon.model.pojo.vo.ArticleTypeVo;
import com.wteam.dragon.model.service.ArticleTypeService;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 陈晓辉
 * @Date 2020/5/1 16:13
 */
@RestController
@Api(tags = "源：文章类型")
@RequestMapping("articleType")
@RequiredArgsConstructor
public class ArticleTypeController {
    private final ArticleTypeService articleTypeService;

    @Log("添加文章类型")
    @ApiOperation("添加文章类型")
    @PostMapping("addArticleType")
    @PreAuthorize("@el.check('addArticleType')")
    public ResultMessage addArticleType(ArticleTypeVo articleTypeVo){
        ArticleType articleType = BeanUtil.from(articleTypeVo, ArticleType.class);
        return articleTypeService.addArticleType(articleType);
    }

    @Log("删除文章类型")
    @ApiOperation("删除文章类型")
    @DeleteMapping("delArticleType")
    @PreAuthorize("@el.check('delArticleType')")
    public ResultMessage delArticleType(Long id){
        return articleTypeService.delArticleType(id);
    }

    @Log("更改文章类型")
    @ApiOperation("更改文章类型")
    @PutMapping("editArticleType")
    @PreAuthorize("@el.check('editArticleType')")
    public ResultMessage editArticleType(ArticleTypeVo articleTypeVo){
        ArticleType articleType = BeanUtil.from(articleTypeVo, ArticleType.class);
        return articleTypeService.editArticleType(articleType);
    }


    @Log("获得文章类型列表")
    @ApiOperation("获得文章类型列表")
    @GetMapping("listArticleType")
    @PreAuthorize("@el.check('listArticleType')")
    public ResultMessage listArticleType(String name){
        return articleTypeService.listArticleType(name);
    }
}
